home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9089 < prev    next >
Encoding:
Text File  |  1996-08-05  |  6.7 KB  |  254 lines

  1. Path: news.WARWICK.NET!usenet
  2. From: acorn@warwick.net (Peter Kohlberger)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Resizing Windows using Turbo C++ 3.1
  5. Date: Fri, 08 Mar 1996 02:24:47 GMT
  6. Organization: Warwick Online
  7. Message-ID: <4ho5ne$r37@news1.warwick.net>
  8. References: <4hiv47$etp@steel.interlog.com>
  9. NNTP-Posting-Host: t9-03.warwick.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. dsheffie@interlog.com wrote:
  13.  
  14. >I am writing a windows program, and am trying to get it to resize my window.
  15.  
  16. >I found the SetWindowPos function in the help files, but it does not seem to work.
  17. >At the top of the help page, the function is listed as 2.X.  Does this mean that this function 
  18. >will not work in 3.X, or only that it was introduced in v 2.1?
  19.  
  20. >If this is not a valid function in Windows 3.X, can anyone tell me of a similar function 
  21. >which will resize my window?
  22.  
  23.  
  24. SetWindowPos should wok fine in Win3.1.  In fact, it works OK in
  25. WIN95.
  26.  
  27. I wrote a program that plays with the window size. It's in three
  28. files: resize.cpp, resize.h, and resize.rc (for a menu).
  29. Here they are:
  30.  
  31. /* file: Resize.cpp */
  32.  
  33. #include <owl.h>
  34. #include "resize.h"
  35.  
  36. // Declare TMyApp, a TApplication descendant
  37. class TMyApp : public TApplication {
  38. public:
  39.     TMyApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  40.       LPSTR lpCmdLine, int nCmdShow)
  41.       : TApplication(AName, hInstance, hPrevInstance, lpCmdLine,
  42. nCmdShow) {};
  43.     virtual void InitMainWindow();
  44.     virtual void InitInstance();
  45. };
  46.  
  47. // Declare TMyWindow, a TWindow descendant
  48. class TMyWindow : public TWindow {
  49. public:
  50.   TMyWindow(PTWindowsObject, LPSTR);
  51.  
  52.   virtual void CMHalf(RTMessage Msg)
  53.    = [CM_FIRST + CM_HALF];
  54.   virtual void CMDouble(RTMessage Msg)
  55.    = [CM_FIRST + CM_DOUBLE];
  56.   virtual void CMTiny(RTMessage Msg)
  57.    = [CM_FIRST + CM_TINY];
  58.   virtual void CMFull(RTMessage Msg)
  59.    = [CM_FIRST + CM_FULL];
  60.   virtual void CMBigger(RTMessage Msg)
  61.    = [CM_FIRST + CM_BIGGER];
  62.   virtual void CMSmaller(RTMessage Msg)
  63.    = [CM_FIRST + CM_SMALLER];
  64. };
  65.  
  66.   void TMyWindow::CMHalf(RTMessage) {
  67.  
  68.   RECT desk,curwindow;
  69.   signed int newright,newbottom;
  70.  
  71.   // Get full extent of desktop
  72.   GetWindowRect(GetDesktopWindow(), &desk);
  73.   // Get current window size
  74.   GetWindowRect(HWindow, &curwindow);
  75.  
  76.   //Let's set a lower bound for the window size of 50 X 50
  77.   //However, note Windows will enforce its own minimum
  78.   if ((newright=curwindow.right/2) < 50)
  79.     newright=50;
  80.   if ((newbottom=curwindow.bottom/2) < 50)
  81.     newbottom=50;
  82.  
  83.   //To keep things simple, all resized windows will originate
  84.   // in the upper-left corner of the desktop (the "0, 0," in next
  85. line)
  86.   SetWindowPos(HWindow, (HWND) NULL, 0, 0,
  87.     newright, newbottom,
  88.     SWP_NOZORDER | SWP_NOACTIVATE);
  89. }
  90.  
  91.   void TMyWindow::CMDouble(RTMessage) {
  92.  
  93.   RECT desk,curwindow;
  94.   signed int newright,newbottom;
  95.  
  96.   // Get full extent of desktop
  97.   GetWindowRect(GetDesktopWindow(), &desk);
  98.   // Get current window size
  99.   GetWindowRect(HWindow, &curwindow);
  100.  
  101.   //Let's set a upper bound for the window size of full screen
  102.   if ((newright=curwindow.right*2) > desk.right)
  103.     newright=desk.right;
  104.   if ((newbottom=curwindow.bottom*2) > desk.bottom)
  105.     newbottom=desk.bottom;
  106.  
  107.   //To keep things simple, all resized windows will originate
  108.   // in the upper-left corner of the desktop (the "0, 0," in next
  109. line)
  110.   SetWindowPos(HWindow, (HWND) NULL, 0, 0,
  111.     newright, newbottom,
  112.     SWP_NOZORDER | SWP_NOACTIVATE);
  113. }
  114.  
  115.   void TMyWindow::CMTiny(RTMessage) {
  116.  
  117.   //To keep things simple, all resized windows will originate
  118.   // in the upper-left corner of the desktop (the "0, 0," in next
  119. line)
  120.   SetWindowPos(HWindow, (HWND) NULL, 0, 0,
  121.     50, 50,
  122.     SWP_NOZORDER | SWP_NOACTIVATE);
  123. }
  124.  
  125.   void TMyWindow::CMFull(RTMessage) {
  126.  
  127.   RECT desk;
  128.  
  129.   // Get full extent of desktop
  130.   GetWindowRect(GetDesktopWindow(), &desk);
  131.  
  132.   //To keep things simple, all resized windows will originate
  133.   // in the upper-left corner of the desktop (the "0, 0," in next
  134. line)
  135.   SetWindowPos(HWindow, (HWND) NULL, 0, 0,
  136.     desk.right, desk.bottom,
  137.     SWP_NOZORDER | SWP_NOACTIVATE);
  138. }
  139.  
  140.   void TMyWindow::CMBigger(RTMessage) {
  141.  
  142.   RECT desk,curwindow;
  143.   signed int newright,newbottom;
  144.  
  145.   // Get full extent of desktop
  146.   GetWindowRect(GetDesktopWindow(), &desk);
  147.   // Get current window size
  148.   GetWindowRect(HWindow, &curwindow);
  149.  
  150.   //Let's set a upper bound for the window size of full screen
  151.   if ((newright=curwindow.right+20) > desk.right)
  152.     newright=desk.right;
  153.   if ((newbottom=curwindow.bottom+20) > desk.bottom)
  154.     newbottom=desk.bottom;
  155.  
  156.   //To keep things simple, all resized windows will originate
  157.   // in the upper-left corner of the desktop (the "0, 0," in next
  158. line)
  159.   SetWindowPos(HWindow, (HWND) NULL, 0, 0,
  160.     newright, newbottom,
  161.     SWP_NOZORDER | SWP_NOACTIVATE);
  162. }
  163.  
  164.   void TMyWindow::CMSmaller(RTMessage) {
  165.  
  166.   RECT desk,curwindow;
  167.   signed int newright,newbottom;
  168.  
  169.   // Get full extent of desktop
  170.   GetWindowRect(GetDesktopWindow(), &desk);
  171.   // Get current window size
  172.   GetWindowRect(HWindow, &curwindow);
  173.  
  174.   //Let's set a lower bound for the window size of 50 X 50
  175.   //However, note Windows will enforce its own minimum
  176.   if ((newright=curwindow.right-20) < 50)
  177.     newright=50;
  178.   if ((newbottom=curwindow.bottom-20) < 50)
  179.     newbottom=50;
  180.  
  181.   //To keep things simple, all resized windows will originate
  182.   // in the upper-left corner of the desktop (the "0, 0," in next
  183. line)
  184.   SetWindowPos(HWindow, (HWND) NULL, 0, 0,
  185.     newright, newbottom,
  186.     SWP_NOZORDER | SWP_NOACTIVATE);
  187. }
  188.  
  189.  
  190. // Construct a TMyWindow, loading its menu
  191. TMyWindow::TMyWindow(PTWindowsObject AParent, LPSTR ATitle)
  192.   : TWindow(AParent, ATitle)
  193. {
  194.   AssignMenu("RESIZECMD");    //see file resize.rc
  195. }
  196.  
  197.  
  198. // Construct the TMyApp's MainWindow of type TMyWindow
  199. void TMyApp::InitMainWindow()
  200. {
  201.   MainWindow = new TMyWindow(NULL, "Resize example");
  202. }
  203.  
  204. /* Initialize each MS-Windows application instance */
  205. void TMyApp::InitInstance()
  206. {
  207.   TApplication::InitInstance();
  208. }
  209.  
  210. // Run the FileApp
  211. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  212.   LPSTR lpCmdLine, int nCmdShow)
  213. {
  214.     TMyApp MyApp ("Resize", hInstance, hPrevInstance,
  215.       lpCmdLine, nCmdShow);
  216.     MyApp.Run();
  217.     return MyApp.Status;
  218. }
  219. /* End of file: Resize.cpp */
  220.  
  221. /* file: Resize.h */
  222. #define CM_HALF       9999
  223. #define CM_DOUBLE     9998
  224. #define CM_TINY       9997
  225. #define CM_FULL       9996
  226. #define CM_BIGGER     9995
  227. #define CM_SMALLER    9994
  228. /* End of file: Resize.h */
  229.  
  230. /* file: Resize.rc */
  231. #include "resize.h"
  232.  
  233. RESIZECMD  MENU LOADONCALL MOVEABLE PURE DISCARDABLE
  234. BEGIN
  235.   POPUP "&Resize"
  236.   BEGIN
  237.     MenuItem  "&Half", CM_HALF
  238.     MenuItem  "&Double", CM_DOUBLE
  239.     MenuItem  "&Tiny", CM_TINY
  240.     MenuItem  "&Full", CM_FULL
  241.     MenuItem  "&Bigger",CM_BIGGER
  242.     MenuItem  "&Smaller",CM_SMALLER
  243.   END
  244. END
  245. /* End of file: Resize.rc */
  246.  
  247. This works for me using Borland Turbo C++ 3.1.
  248.  
  249. Good luck.
  250.  
  251. Peter Kohlberger
  252. acorn@warwick.net
  253.  
  254.